package com.qfedu.biz.impl;

import com.qfedu.biz.CustomerBiz;
import com.qfedu.entity.CustomerEntity;
import com.qfedu.mapper.CustomerPojoMapper;
import com.qfedu.pojo.CustomerPojo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CustomerBizimpl implements CustomerBiz {
    @Autowired
    private CustomerPojoMapper customerPojoMapper;

    //登录
    @Override
    public CustomerEntity queryCustomer(CustomerEntity customerEntity) {
        CustomerPojo customerPojo = customerPojoMapper.queryCustomer(entityToPojo(customerEntity));
        CustomerEntity customerEntity2 = pojoToEntity(customerPojo);
        return customerEntity2;
    }

    @Override
    public Boolean insertCustomer(CustomerEntity customerEntity) {
        Boolean aBoolean = customerPojoMapper.insertCustomer(customerEntity);
        return aBoolean;
    }

    @Override
    public Boolean updateCus(CustomerEntity customerEntity) {
        Boolean aBoolean = customerPojoMapper.updateCus(customerEntity);
        return aBoolean;
    }

    //pojo转换陈entity
    private CustomerEntity pojoToEntity(CustomerPojo customerPojo){
        CustomerEntity customerEntity = new CustomerEntity(customerPojo.getCid(), customerPojo.getCname(), customerPojo.getCaccount(), customerPojo.getCpass(), customerPojo.getCemail(), customerPojo.getCphone(), customerPojo.getCsex(), customerPojo.getCimage(), customerPojo.getCstatus(),customerPojo.getCdesc());
        return customerEntity;

    }

    //entity转换成Pojo
    private CustomerPojo entityToPojo(CustomerEntity customerEntity){
        CustomerPojo customerPojo = new CustomerPojo(customerEntity.getCid(), customerEntity.getCname(), customerEntity.getCaccount(), customerEntity.getCpass(), customerEntity.getCemail(), customerEntity.getCphone(), customerEntity.getCsex(), customerEntity.getCimage(), customerEntity.getCstatus(),customerEntity.getCdesc());
        return customerPojo;
    }
}
